﻿namespace PowerSong.SongDatabase
    {
    using System.IO;
    using System;

    public class SubStyle
        {

        public string Name { get; set; }

        public TextVisibility Visibility { get; set; }

        public SubStyleMargin Margin { get; set; }

        public string FontName { get; set; }

        public double FontSize { get; set; }

        public uint FontColor { get; set; }

        public FontEffectType FontStyle { get; set; }

        public TextEffectType FontEffect { get; set; }

        public uint FontEffectColor { get; set; }

        public Alignment TextAlignment { get; set; }
        
        public SubStyleFadeDetails FadeIn { get; set; }

        public SubStyleFadeDetails FadeOut { get; set; }        

        public SubStyleFadeDetails CrossFade { get; set; }

        public SubStyle(string name)
            {
            this.Name = name;
            this.Visibility = TextVisibility.Always;
            this.Margin = new SubStyleMargin(0, 0, 0, 0);
            this.FontName = "Times New Roman";
            this.FontSize = 0.1;
            this.FontColor = 0;
            this.FontStyle = FontEffectType.None;
            this.FontEffect = TextEffectType.None;
            this.FontEffectColor = 0;
            this.TextAlignment = Alignment.CenterMiddle;
            this.FadeOut = new SubStyleFadeDetails(FadeType.Fade, 1000);
            this.FadeIn = new SubStyleFadeDetails(FadeType.Fade, 1000);
            this.CrossFade = new SubStyleFadeDetails(FadeType.Fade, 500);
            }

        internal SubStyle(BinaryReader reader)
            {
            this.Name = reader.ReadString();
            this.Visibility = (TextVisibility)Enum.Parse(typeof(TextVisibility), reader.ReadString());
            this.Margin = new SubStyleMargin(reader);
            this.FontName = reader.ReadString();
            this.FontSize = reader.ReadDouble();
            this.FontColor = reader.ReadUInt32();
            this.FontStyle = (FontEffectType)reader.ReadInt32();
            this.FontEffect = (TextEffectType)Enum.Parse(typeof(TextEffectType), reader.ReadString());
            this.FontEffectColor = reader.ReadUInt32();
            this.TextAlignment = (Alignment)Enum.Parse(typeof(Alignment), reader.ReadString());
            this.FadeIn = new SubStyleFadeDetails(reader);
            this.FadeOut = new SubStyleFadeDetails(reader);
            this.CrossFade = new SubStyleFadeDetails(reader);
            }

        internal void WriteDetails(BinaryWriter writer)
            {
            writer.Write(this.Name);
            writer.Write(this.Visibility.ToString());
            this.Margin.WriteDetails(writer);
            writer.Write(this.FontName);
            writer.Write(this.FontSize);
            writer.Write(this.FontColor);
            writer.Write((int)this.FontStyle);
            writer.Write(this.FontEffect.ToString());
            writer.Write(this.FontEffectColor);
            writer.Write(this.TextAlignment.ToString());
            this.FadeIn.WriteDetails(writer);
            this.FadeOut.WriteDetails(writer);
            this.CrossFade.WriteDetails(writer);
            }

        }

    }
